package com.glela.api.pay.wechat.component;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.DigestException;
import java.util.Map;

import com.glela.api.model.PayAppKeyInfo;
import com.glela.api.pay.wechat.vo.JsapiTicketVo;
import com.glela.api.pay.wechat.vo.WeChatTokenVo;
import com.glela.api.pay.wechat.vo.WeChatUserInfoVo;

/**
 *@author liujie
 *@2016年11月1日
 */
public interface WeChat {

	public static final String SUCCESS_XML="<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>";
	
	public static final String FAIL_XML="<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[FAIL]]></return_msg></xml>";
	
	/**
	 * 获得分享accessToken
	 * @param appid
	 * @param secret
	 * @return
	 * @throws IOException
	 */
	public WeChatTokenVo getAccessToken(String appid ,String secret) throws IOException;
	
	/**
	 * 获得分享签名
	 * @param params
	 * @return
	 * @throws DigestException 
	 * @throws UnsupportedEncodingException 
	 */
	public String getShareSign(Map<String, String> params) throws DigestException, UnsupportedEncodingException;
	
	/**
	 * 获得分享用的JsapiTicket
	 * @param accessToken
	 * @return
	 * @throws IOException
	 */
	public JsapiTicketVo getJsapiTicket(String accessToken) throws IOException;
	
	/**
	 * 微信授权   通过code换取网页授权access_token
	 * @param appid
	 * @param secret
	 * @param code
	 * @return
	 */
	public WeChatTokenVo getWeChaAuthority(String appid , String secret ,String code ) throws IOException;
	
	/**
	 * 刷新access_token
	 * @param appid
	 * @param refresh_token
	 * @return
	 * @throws IOException
	 */
	public WeChatTokenVo getRefreshToken(String appid , String refreshToken ) throws IOException;
	
	/**
	 * 拉取用户信息(需scope为 snsapi_userinfo)
	 * @param accessToken   网页授权接口调用凭证
	 * @param openid    微信用户唯一id
	 * @return
	 * @throws IOException
	 */
	public WeChatUserInfoVo getUserInfo(String accessToken , String openId ) throws IOException;
	
	/**
	 * 检验授权凭证（access_token）是否有效
	 * @param accessToken
	 * @param openid
	 * @return
	 * @throws IOException
	 */
	public WeChatTokenVo getIsOkAccessToken(String accessToken , String openId ) throws IOException;
	
	/**
	 * <dl><dt>创建微信支付信息</dt></dl>
	 * @param payAppKeyInfo 微信帐号信息
	 * @param orderObjectOrderSn 结算单号
	 * @param payNo 支付流水号
	 * @param totalFee 支付金额（分）
	 * @param spbillCreateIp 客户端IP
	 * @param openId 公众号ID
	 * @return Map<String,Object>
	 * @throws IOException 
	 * @author zls
	 * @date 2017年12月5日 下午11:13:31
	 */
	public Map<String, Object> weChaPay(PayAppKeyInfo payAppKeyInfo, String orderObjectOrderSn, String payNo, int totalFee, String spbillCreateIp, String openId) throws IOException;
	
	/**
	 * 微信支付会员
	 * @param map
	 * @param key 
	 * @return
	 * @throws IOException 
	 */
	public Map<String, Object> weChaPayVip(PayAppKeyInfo payAppKeyInfo,String orderSn
			,int totalFee,String spbillCreateIp,String openId) throws IOException;
    
	/**
	 * 微信退款
	 * @param map
	 * @param key 
	 * @return
	 * @throws IOException 
	 */
	public Map<String, Object> weChaPayRefund(PayAppKeyInfo payAppKeyInfo, String orderSn, int totalFee, int refundFee,
			String afterSn, String payId) throws IOException;
	
	public Map<String, Object> weChaPayTransfers(PayAppKeyInfo payAppKeyInfo, String orderSn,
			int totalFee,String spbillCreateIp,String openId) throws IOException;
	
	public String getWeChatShortLink(String accessToken,String long_url) throws Exception;
	
	Map<String, Object> weChaPayRefundQuery(PayAppKeyInfo payAppKeyInfo,
			String orderSn) throws  Exception;

	Map<String, Object> weChaPayOrderQuery(PayAppKeyInfo payAppKeyInfo,
			String orderSn) throws Exception;
}
